home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / iwf12.zip / MODULES / PROFILER.C < prev    next >
C/C++ Source or Header  |  1994-02-09  |  12KB  |  467 lines

  1. /*
  2. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. PROFILER.C
  4.  
  5. AUTHOR: Craig Muller P. Eng. 1991,1992,1993
  6.         cmuller@ccu.umanitoba.ca
  7.         Computer Vision Laboratory
  8.         Mech. Engn.,Univ. of Manitoba
  9.         Winnipeg, Manitoba. R3T 2N2
  10.  
  11. DESCRIPTION:
  12. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  13. */
  14. #include <windows.h>
  15.  
  16. #pragma hdrstop
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20.  
  21. #include "iwf.h"
  22.  
  23. // Defines.
  24. #define  MODULENAME "PROFILER"
  25.  
  26. // Exported Procedures.
  27. BOOL FAR PASCAL _export DP_Profiler(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam);
  28. BOOL FAR PASCAL _export DP_ProfilerAbout(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  29.  
  30. // Public procedures.
  31. static void Profile(HWND hWnd,POINT *pt0,POINT *pt1);
  32. static void Message(char *sz,int font);
  33.  
  34. // Private variables.
  35. HWND  hDlgProfiler=NULL;
  36. static HWND  hWndStatBar;
  37.  
  38. // Flags for display options
  39. static BOOL fCapture  = FALSE;
  40. static BOOL fRefresh  = TRUE;
  41. static BOOL fBright   = TRUE;
  42. static BOOL fGradient = TRUE ;
  43.  
  44. static BYTE     dn[1024];
  45. static int     gs[1024];
  46.  
  47. // Drawing colors
  48. static COLORREF crBright = RGB(0xff,0xff,0x00);
  49. static COLORREF crGrad   = RGB(0x00,0xff,0x00);
  50. static COLORREF crScan   = RGB(0xff,0x00,0x00);
  51.  
  52. // Drawing cccdinates
  53. static POINT pt0;
  54. static POINT pt1;
  55.  
  56. // Application instance handle.
  57. static HINSTANCE hInstance;
  58.  
  59. /*
  60. --------------------------------------------------------------------------
  61. Profiler()
  62. ~~~~~~~~
  63.  
  64. PROFILER STARTUP PROCESSING PROCEDURE.
  65. This is called when the user selects this option from the main menu.
  66. This procedure check to see if the popup window exists. If so it simply
  67. passes focus to the window and returns since there is nothing more to do.
  68. If it does not exist then it proceeds to create the popup window and menu
  69. and displays it on the screen. The popup window acts like a sub-program
  70. within the main program and receives messages from the main program.
  71. --------------------------------------------------------------------------
  72. */
  73. void Profiler(HWND hWndParent)
  74.    {
  75.     FARPROC lpProc;
  76.    RECT rc0,rc1;
  77.    int w,h;
  78.  
  79.    if (IsWindow(hDlgProfiler))
  80.       {
  81.       SetFocus(hDlgProfiler);
  82.       }
  83.    else
  84.       {
  85.         hInstance = GetWindowWord(hWndParent,GWW_HINSTANCE);
  86.       lpProc = MakeProcInstance(DP_Profiler,hInstance);
  87.       hDlgProfiler = CreateDialog(hInstance,"PROFILER",hWndParent,lpProc);
  88.       GetWindowRect(hWndParent,&rc0);
  89.       GetWindowRect(hDlgProfiler,&rc1);
  90.       w = rc1.right - rc1.left;
  91.       h = rc1.bottom - rc1.top;
  92.       MoveWindow(hDlgProfiler,rc0.right-10-w,rc0.top+45,w,h,TRUE);
  93.       ShowWindow(hDlgProfiler,SW_SHOW);
  94.       }
  95.    }
  96.  
  97.  
  98.  
  99.  /*
  100. ===============================================================================
  101. BOOL FAR PASCAL _export DP_Profiler(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam)
  102.  
  103. Decription:
  104. This window procedure handles all the messaging for the Profiler Image Viewing
  105. module. Special code is called which produces a red and blue composite
  106. image from both left and right grey scale image. The user the puts on red
  107. and blue 3D glasses to view the image in 3D.
  108. ===============================================================================
  109. */
  110. BOOL FAR PASCAL _export DP_Profiler(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam)
  111.    {
  112.  
  113.     switch (wMsg)
  114.         {
  115.         case WM_INITDIALOG:                        // WINDOW CREATION.
  116.         // Initialize check boxes.
  117.       CheckDlgButton(hWnd,51,fRefresh);
  118.         CheckDlgButton(hWnd,52,fBright );
  119.         CheckDlgButton(hWnd,53,fGradient);
  120.         hWndStatBar = CreateStatBar(hWnd);         // Add a status line
  121.       PostMessage(hWnd,WM_USER,0,0);             // Ready to show the window
  122.         break;
  123.  
  124.       case WM_USER:
  125.       ShowWindow(hWnd,SW_SHOW);                  // Show the window
  126.         hWndMod = hWnd;                            // Make this module active.
  127.       break;
  128.  
  129.         case WM_CTLCOLOR:
  130.         switch(HIWORD(lParam))
  131.          {
  132.          case CTLCOLOR_STATIC:
  133.          SetBkColor((HDC)wParam,GetSysColor(COLOR_BTNFACE));
  134.          return (LRESULT) GetStockObject(LTGRAY_BRUSH);
  135.          }
  136.       return (LRESULT) NULL;
  137.  
  138.       case WM_PAINT:                             // IMAGE NEEDS PAINTING.
  139.       {
  140.       RECT rc;
  141.       PAINTSTRUCT ps;
  142.  
  143.       BeginPaint(hWnd,&ps);
  144.  
  145.       if (IsIconic(hWnd))
  146.             {
  147.             DrawIcon(ps.hdc,0,0,LoadIcon(hInstance,"PROFILER"));
  148.          }
  149.       else
  150.          {
  151.          GetClientRect(hWnd,&rc);
  152.          FillRect(ps.hdc,&rc,GetStockObject(LTGRAY_BRUSH));
  153.          }
  154.  
  155.         EndPaint(hWnd,&ps);                        // Painting complete.
  156.         }
  157.         break;
  158.  
  159.         case WM_LBUTTONUP:                         // LEFT BUTTON UP.
  160.         if (IsWindow((HWND)wParam))
  161.             {
  162.             if (!fCapture)
  163.                 {
  164.                 char sz[40];
  165.  
  166.                 SetCapture((HWND)wParam);
  167.                 fCapture = TRUE;
  168.                 pt0 = MAKEPOINT(lParam);
  169.                 pt1 = MAKEPOINT(lParam);
  170.                 sprintf(sz,"Coordinates: x:%d  y:%d",pt0.x,pt0.y);
  171.                 Message(sz,0);
  172.                 if (fRefresh)
  173.                     {
  174.                     RefreshImage((HWND)wParam);
  175.                     UpdateWindow((HWND)wParam);
  176.                     }
  177.                 }
  178.             else
  179.                 {
  180.                 int cx,cy;
  181.                 char sz[40];
  182.                 HDC hDC;
  183.                 IMAGE *image;
  184.                 RECT rc;
  185.  
  186.                 hDC = GetDC((HWND)wParam);
  187.                 image = GetImage(hWndSrc);           // Get attached data set.
  188.  
  189.                 // Map image coords into window area
  190.                 GetClientRect((HWND)wParam,&rc);
  191.                 SetMapMode(hDC,MM_ISOTROPIC);
  192.                 SetWindowExt(hDC,image->hres,image->vres);
  193.                 SetViewportExt(hDC,rc.right,rc.bottom);
  194.  
  195.                 SetROP2(hDC,R2_NOT);
  196.                 pt1 = MAKEPOINT(lParam);
  197.                 cx = pt1.x - pt0.x;
  198.                 cy = pt1.y - pt0.y;
  199.                 if (cx>=cy) pt1.y = pt0.y;
  200.                 if (cx< cy) pt1.x = pt0.x;
  201.                 MoveTo(hDC,pt0.x,pt0.y);
  202.                 LineTo(hDC,pt1.x,pt1.y);
  203.                 ReleaseDC((HWND)wParam,hDC);
  204.  
  205.                 sprintf(sz,"Coordinates: x:%d  y:%d",pt1.x,pt1.y);
  206.                 Message(sz,0);
  207.                 ReleaseCapture();
  208.                 fCapture = FALSE;
  209.                 Profile((HWND)wParam,&pt0,&pt1);
  210.                 }
  211.             }
  212.         else
  213.             {
  214.             hWndMod = hWnd;                        // Make this module active.
  215.             }
  216.         break;
  217.  
  218.         case WM_MOUSEMOVE:
  219.         if (IsWindow((HWND)wParam))
  220.             {
  221.             if (fCapture)
  222.                 {
  223.                 int cx,cy;
  224.                 HDC hDC;
  225.                 IMAGE *image;
  226.                 RECT rc;
  227.  
  228.                 hDC = GetDC((HWND)wParam);
  229.                 image = GetImage(hWndSrc);           // Get attached data set.
  230.  
  231.                 // Map image coords into window area
  232.                 GetClientRect((HWND)wParam,&rc);
  233.                 SetMapMode(hDC,MM_ISOTROPIC);
  234.                 SetWindowExt(hDC,image->hres,image->vres);
  235.                 SetViewportExt(hDC,rc.right,rc.bottom);
  236.  
  237.                 // Erase the previous indicator line and draw a new one
  238.                 SetROP2(hDC,R2_NOT);
  239.                 MoveTo(hDC,pt0.x,pt0.y);
  240.                 LineTo(hDC,pt1.x,pt1.y);
  241.                 pt1 = MAKEPOINT(lParam);
  242.                 cx = pt1.x - pt0.x;
  243.                 cy = pt1.y - pt0.y;
  244.                 if (cx>=cy) pt1.y = pt0.y;
  245.                 if (cx< cy) pt1.x = pt0.x;
  246.                 MoveTo(hDC,pt0.x,pt0.y);
  247.                 LineTo(hDC,pt1.x,pt1.y);
  248.  
  249.                 ReleaseDC((HWND)wParam,hDC);
  250.                 }
  251.             }
  252.         break;
  253.  
  254.         case WM_CHAR:
  255.         case WM_COMMAND:                           // MENU COMMAND SELECTED.
  256.         switch (wParam)
  257.             {
  258.             case 51:
  259.             fRefresh = (IsDlgButtonChecked(hWnd,wParam)) ? 1 : 0;
  260.             break;
  261.  
  262.             case 52:
  263.             fBright  = (IsDlgButtonChecked(hWnd,wParam)) ? 1 : 0;
  264.             break;
  265.  
  266.             case 53:
  267.             fGradient = (IsDlgButtonChecked(hWnd,wParam)) ? 1 : 0;
  268.             break;
  269.  
  270.             case 111:
  271.             PickColor(hWnd,&crBright);
  272.             break;
  273.  
  274.             case 112:
  275.             PickColor(hWnd,&crGrad);
  276.             break;
  277.  
  278.             case 113:
  279.             PickColor(hWnd,&crScan);
  280.             break;
  281.  
  282.          case 999:
  283.          CallDialogBox(hWnd,DP_ProfilerAbout,"PROFILER_ABOUT");
  284.          break;
  285.             }
  286.       break;
  287.  
  288.       case WM_SETFOCUS:                          // FOCUS HAS BEEN SET.
  289.       hWndMod = hWnd;                            // Make this module active.
  290.       break;
  291.  
  292.       case WM_KILLFOCUS:                         // FOCUS HAS BEEN KILLED.
  293.       break;
  294.  
  295.       case WM_CLOSE:
  296.       DestroyWindow(hWnd);
  297.       break;
  298.  
  299.       case WM_DESTROY:
  300.         hDlgProfiler = NULL;
  301.       break;
  302.       }
  303.  
  304.    lParam=lParam;
  305.  
  306.     return(NULL);
  307.     }
  308.  
  309.  
  310. /*
  311. ==========================================================================
  312. DP_ProfilerAbout()
  313. ~~~~~~~~~~~~~~~~~~
  314.  
  315. Description:
  316. This box appears to inform the user about the origins of the software.
  317. Wait for user to click on "Ok" button, then close the dialog box.
  318. ==========================================================================
  319. */
  320. BOOL FAR PASCAL _export DP_ProfilerAbout(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam)
  321.     {
  322.    switch (wMsg)
  323.         {
  324.       case WM_INITDIALOG: return (TRUE);
  325.         case WM_COMMAND:    EndDialog(hDlg,TRUE); return (TRUE);
  326.         }
  327.  
  328.    // Supress compiler messages
  329.     lParam=lParam;
  330.     wParam=wParam;
  331.     return (FALSE);
  332.     }
  333.  
  334.  
  335.  
  336.  
  337. /*
  338. ---------------------------------------------------------------------
  339. Profile()
  340. ~~~~~~~~~
  341. Description:
  342. This procedure draws an image brightness profile on the screen.
  343. ---------------------------------------------------------------------
  344. */
  345. static void Profile(HWND hWnd,POINT *pt0,POINT *pt1)
  346.     {
  347.     int    i,cx,cy;
  348.     RECT   rc;
  349.     HDC    hDC;
  350.     HPEN   hPenBright,hPenScan,hPenGrad;
  351.     IMAGE  *image;
  352.  
  353.     image = (IMAGE *)GetWindowWord(hWnd,GWW_IMAGE);// Get attached data set.
  354.     hDC = GetDC(hWnd);                             // Get the image window DC
  355.  
  356.     // Map image to window area
  357.     GetClientRect(hWnd,&rc);                       // Get Client image rect
  358.     SetMapMode(hDC,MM_ISOTROPIC);                  // Set map mode to scale
  359.     SetWindowExt(hDC,image->hres,image->vres);     // Set logical extents
  360.     SetViewportExt(hDC,rc.right,rc.bottom);        // Set physical extents
  361.  
  362.     hPenBright = CreatePen(PS_SOLID,1,crBright);
  363.     hPenGrad   = CreatePen(PS_SOLID,1,crGrad);
  364.     hPenScan   = CreatePen(PS_SOLID,1,crScan);
  365.  
  366.     cx = pt1->x - pt0->x;
  367.     cy = pt1->y - pt0->y;
  368.  
  369.     if (cx>0)
  370.         {
  371.         GetImageRow(image,pt0->x,pt0->y,dn,cx);
  372.  
  373.         for (i=0; i<cx; i++)
  374.             gs[i] = (int)(image->LUT[dn[i]].peRed+
  375.                           image->LUT[dn[i]].peGreen+
  376.                           image->LUT[dn[i]].peBlue)/3;
  377.  
  378.         SelectObject(hDC,hPenScan);
  379.         MoveTo(hDC,pt0->x,pt0->y);
  380.         LineTo(hDC,pt1->x,pt1->y);
  381.  
  382.         if (fBright)
  383.             {
  384.             SelectObject(hDC,hPenBright);                      /* select yellow pen */
  385.          if (pt0->y > image->vres/2)
  386.             {
  387.                MoveTo(hDC,pt0->x,pt0->y-gs[0]/2);
  388.             for (i=0; i<cx-1; i++)
  389.                    LineTo(hDC,pt0->x+i,pt0->y-gs[i]/2);
  390.             }
  391.          else
  392.             {
  393.                MoveTo(hDC,pt0->x,pt0->y+128-gs[0]/2);
  394.             for (i=0; i<cx-1; i++)
  395.                    LineTo(hDC,pt0->x+i,pt0->y+128-gs[i]/2);
  396.             }
  397.             }
  398.  
  399.         if (fGradient)
  400.             {
  401.             SelectObject(hDC,hPenGrad);
  402.             MoveTo(hDC,pt0->x,pt0->y-(gs[1]-gs[0]));
  403.             for (i=0; i<cx-1; i++)
  404.                 LineTo(hDC,pt0->x+i,pt0->y-(gs[i+1]-gs[i]));
  405.             }
  406.         }
  407.  
  408.     if (cy>0)
  409.         {
  410.         GetImageCol(image,pt0->x,pt0->y,dn,cy);
  411.  
  412.         for (i=0; i<cy; i++)
  413.             gs[i] = (int)(image->LUT[dn[i]].peRed+
  414.                           image->LUT[dn[i]].peGreen+
  415.                           image->LUT[dn[i]].peBlue)/3;
  416.  
  417.         SelectObject(hDC,hPenScan);
  418.         MoveTo(hDC,pt0->x,pt0->y);
  419.         LineTo(hDC,pt1->x,pt1->y);
  420.  
  421.         if (fBright)
  422.             {
  423.             SelectObject(hDC,hPenBright);
  424.          if (pt0->x < image->hres/2)
  425.             {
  426.                MoveTo(hDC,pt0->x+gs[0]/2,pt0->y);
  427.                for (i=0; i<cy-1; i++)
  428.                    LineTo(hDC,pt0->x+gs[i]/2,pt0->y+i);
  429.             }
  430.          else
  431.             {
  432.                MoveTo(hDC,pt0->x-128+gs[0]/2,pt0->y);
  433.                for (i=0; i<cy-1; i++)
  434.                    LineTo(hDC,pt0->x-128+gs[i]/2,pt0->y+i);
  435.             }
  436.             }
  437.  
  438.         if (fGradient)
  439.             {
  440.             SelectObject(hDC,hPenGrad);
  441.             MoveTo(hDC,pt0->x+(gs[1]-gs[0]),pt0->y);
  442.             for (i=0; i<cy-1; i++)
  443.                 LineTo(hDC,pt0->x+(gs[i+1]-gs[i]),pt0->y+i);
  444.             }
  445.         }
  446.  
  447.     SelectObject(hDC,GetStockObject(BLACK_PEN));
  448.  
  449.     DeleteObject(hPenBright);
  450.     DeleteObject(hPenGrad);
  451.     DeleteObject(hPenScan);
  452.  
  453.     ReleaseDC(hWnd,hDC);
  454.     }
  455.  
  456.  
  457. /*
  458. --------------------------------------------------------------------------
  459.  
  460. --------------------------------------------------------------------------
  461. */
  462. static void Message(char *sz,int font)
  463.     {
  464.     SendMessage(hWndStatBar,WM_USER,(WPARAM)sz,font);
  465.     }
  466.  
  467.